package com.ucap.weking.guangan.dialog;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ucap.weking.guangan.R;
import com.ucap.weking.guangan.base.BaseDialog;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by weking on 2017/11/9.
 */

public class VersionInfoDialog extends BaseDialog {

    @InjectView(R.id.tv_version_content)
    TextView tvContent;
    @InjectView(R.id.btn_dismiss)
    Button btnDismiss;
    @InjectView(R.id.btn_update)
    Button btnUpdate;
    String apkUri;
    String content = "---------------------------------";

    protected VersionInfoDialog(Context context, String content, String apkUri) {
        super(context);
        this.content = content;
        this.apkUri = apkUri;
    }

    public static void showDialog(Context context, String content, String apkUri) {
        VersionInfoDialog dialog = new VersionInfoDialog(context, content, apkUri);
        dialog.show();
    }

    @Override
    public void setView() {
        View contentView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_version_info, null);
        setContentView(contentView);
        ButterKnife.inject(this, contentView);
    }

    @Override
    public void setListener() {
        btnDismiss.setOnClickListener(this);
        btnUpdate.setOnClickListener(this);
    }

    @Override
    public void setData() {
        tvContent.setText(content);
    }

    @Override
    public void setClick(View v) {
        if (v == btnDismiss) {
            dismiss();
        } else if (v == btnUpdate) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(apkUri));
            getContext().startActivity(intent);
        }
    }
}
